package community.hospital.service.domain.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import community.hospital.entity.Doctor;
import community.hospital.entity.request.ListDoctorRequest;
import community.hospital.service.domain.DoctorService;
import community.hospital.mapper.DoctorMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ydj
* @description 针对表【doctor(医生信息表)】的数据库操作Service实现
* @createDate 2023-01-27 14:57:21
*/
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor>
    implements DoctorService{

    @Override
    public Page<Doctor> listDoctor(ListDoctorRequest request) {
        Integer state = request.getState();
        Long departmentId = request.getDepartmentId();
        Long hospitalId = request.getHospitalId();
        Page<Doctor> doctorPage = new Page<>(request.getPageNumber(), request.getPageSize());
        lambdaQuery()
                .eq(state!=null,Doctor::getState,state)
                .eq(departmentId!=null,Doctor::getDepartment1Id,departmentId)
                .or(departmentId!=null, t->t.eq(departmentId!=null,Doctor::getDepartment2Id,departmentId))
                .eq(hospitalId!=null,Doctor::getHospitalId,hospitalId)
                .eq(StrUtil.isNotBlank(request.getName()),Doctor::getName,request.getName())
                .eq(StrUtil.isNotBlank(request.getProfession()),Doctor::getProfession,request.getProfession())
                .page(doctorPage);
        return doctorPage;
    }

    @Override
    public List<Doctor> listDoctorByCondition(ListDoctorRequest request) {

        return lambdaQuery().eq(request.getHospitalId() != null, Doctor::getHospitalId, request.getHospitalId())
                .eq(request.getDepartment1Id() != null, Doctor::getDepartment1Id, request.getDepartment1Id())
                .eq(request.getDepartment2Id() != null, Doctor::getDepartment2Id, request.getDepartment2Id())
                .eq(request.getDepartmentId()!=null,Doctor::getDepartment1Id,request.getDepartmentId())
                .or(request.getDepartmentId()!=null,t->t.eq(Doctor::getDepartment2Id,request.getDepartmentId()))
                .eq(request.getState()!=null,Doctor::getState,request.getState())
                .list();
    }

}




